try {
    console.assert(1);
} catch(e) {
    if (typeof loadFirebugConsole == 'function') {
         loadFirebugConsole();
    }  else {
        console = {
            log: function() {},
            debug: function() {},
            info: function() {},
            warn: function() {},
            assert: function() {}
        }
    }
}
/**
 * 列印debug資訊到控制台(僅限Firefox)
 * @param {Object} str
 */
function logDebug(str){
    if (!Ext.isIE) {
        console.log(str);
    }
}

/**
 * 軟電話操作(相容所有交換機)
 * @author kevin.ding
 * @date 2008-09-03
 */


/** ************softphone相關全域變數************ */

// 物理callid
// PHYSIC_CALL_ID = '';
// 邏輯callid
LOGIC_CALL_ID = '';

// callData 保存電話資訊,callid,來電號碼之類
CALL_DATA = {
	calledNum : '',
	callerNum : '',
	inlineFlag : '',
	callId : '',
	callDirection : '',
	callIntime : '',
	vipCode : '',
	vipType : '',
	callType : '',
	recordId:'',//錄音ID
	recordFileName:'',//錄音檔案名
	seqNumber:'',
	inlineOrderId:'',//訂單編號 for 呼哈
	ringType:'',//響鈴狀態類型 for huha	
	isTurnIVR:'N',//當前協力廠商通話是否是轉入IVR，add by leo
	pbxCallId:'',//轉接或者會議，協力廠商通話時會生成新的callId將這些CallId保存起來;
	inLineType:'',//杂志别
	subscriberNo:''//订户编号
	
};
//add by lili VIP客戶資訊 20090827
G_VIP_CUS_INFO_20090827={
	cusName:'',
	cusCallNumber:''
}

// acw是否可以結束標記
ACW_ENDABLE = true;

//進線還是查詢'query'表示查詢,'inline'表示進線
INLINE_TYPE = '';

// 控制電話是否在使用狀態(控制電話作業是否需要保存後才能關閉)
IS_CALLING = false;

// 保存當前的進線客戶
CUURENT_INLINE_CUSTOMER = null;

// 保存欄位的key
INLINE_CUSTOMER_FIELDS = new Array();

// 是否編輯進線客戶
IS_EDIT_INLINE_USER = false;

// 進線客戶是否是vip
IS_INLINE_VIP = false;

// caseid全域變數
SYSTEM_CASE_ID = '0';

// 當前活動
CURRENT_ACTIVITY_ID = '';

// 外撥的電話號碼
CALLED_NUMBER = '';

//保存来电号码的标识.for 商周
CALL_IN_NUMBERS = new Array;

/** ****************全域變數聲明區結束******************* */

/**
 * 構建softphone介面
 */
ALERT_TYPE = '';
Ext.SoftPhoneAll = function() {
	var ivrNumber = "4021";
	// 控制demo和真實環境
	//AIC_SYSTEM = 'Demo';
	
	AIC_SYSTEM = 'Aspect';
	//AIC_SYSTEM = 'Avaya';

	var getCsrInfoUrl = 'busSoftPhone/spOpt!getCsrInfo.action';
	var getInfoUrl = 'sysUser/sysUser03/User!showAll.action';
	
	// 獲取環境變數Url
	var getVarUrl = '../ib/pages/inline/ibInline!getVariableValueByTypeId.action'

	// 保存座席員分機號
	var csrSubCode = 'initial';
	// 保存軟電話登錄帳戶
	var csrSPLogin = '';
	// 保存軟電話密碼
	var csrSPPwd = '';
	// 保存交換機位址
	var csrUrl = '';
	//當前分機位置
	var csrCurStation = '';
	//vdn 號碼(從環境變數裡面來);
	var vdnNumber = '';

	// 保存客戶電話清單
	var custNumbers = new Array();
	
	//在手動改變狀態時需要過濾的狀態
	var notListStatus = ['10001','10002','20005','20015','20006','20007','20008','park','20012'];
	
	//表示是否回訪
	var isCallCare = false;
	
	//表示登錄後點了就緒
	isFirstAvailable = false;
	
	//表示是否登錄了軟電話
	var softPhoneIsLogon = false;
	
	//保存就緒狀態
	var availableStatus = null;
	
	//保存未就緒狀態
	var unAvailableStatus = new Array;
	
	return {
		//供外部模组调用,直接打开拨号界面,商周客制化:双击名单进入电话作业的时候调用
		openDail:function(){
			var dailAct = Ext.getCmp('actDail');
			
			if(dailAct&&!dailAct.disabled){
				dailAct.handler();
			}
		},
	    insertAttributeValue: function(attributeValue){
	     
	     var callidKey=CALL_DATA.callId;
	       //var callidKey="102";
	       //alert(callidKey);
	       //alert(attributeValue);
	       if(callidKey==null){
	         return;
	       }
	       
	           Ext.Ajax.request({
                    url: '../ib/pages/inline/ibInline!insertAttributeValue.action',
                    success: function(result, obj){
                        var jsonFromServer = Ext.util.JSON.decode(result.responseText);
                        if (jsonFromServer.success) {
						//Grandsys.sys.Utils.alertSaveSuccess();
                        }
                        else {
                        Grandsys.sys.Utils.alertSaveFailure();
                        }
                    },
                    failure: function(){
                    Grandsys.sys.Utils.alertSaveFailure();
                    },
                    params:{
                     callidKey : callidKey,
                     attributeValue : attributeValue
                    }
                });
	       
	       
	    },
		log: new Logger('softPhoneforAll.js'),
		// 客戶電話清單
		custNumbers : custNumbers,
		/**
		 * 同步獲取狀態
		 */
		getStatusByCode : function(statusCode) {
			// 獲取當前交換機狀態對應的系統狀態(同步獲取)
			var conn = Ext.lib.Ajax.getConnectionObject().conn;

			var url = 'statusManager/statusMgr!findStatusByCallState.action?callState='+statusCode;//
			conn.open("GET", url, false);// false表示同步調用
			conn.send(null);
			var data = Ext.util.JSON.decode(conn.responseText);

			return data.status;
		},
		/**
		 * 返回csr是否已經登錄了軟電話
		 */
		isLogon:function(){
			return softPhoneIsLogon;
		},
		checkLinkStatus : function() {
			return GrandsysInc.EICConn.ConnectionValid;
		},
		//控制轉接和會議的按鈕
        optBtn: function(item){
            var btnConsult = Ext.getCmp('btnConsult');
            var btnAccept = Ext.getCmp('btnAccept');
            var btnCancel = Ext.getCmp('btnCancel');
		
			//alert('optBtn::'+item);
	
			if (this.log.isDebugEnabled()) {
                this.log.debug('轉接按鈕操作::'+item);
            }


           	try {
				 switch (item) {
			                //協議轉接/會議後
			                case 1:
			                    btnConsult.setDisabled(true);
			                    btnAccept.setDisabled(false);
			                    btnCancel.setDisabled(false);
			                    break;
			                //確定/取消轉接/會議後
			                case 2:
			                    btnConsult.setDisabled(false);
			                    btnAccept.setDisabled(true);
			                    btnCancel.setDisabled(false);
			                    break;			                 
			                //掛斷後
			                case 5:
			                    btnConsult.setDisabled(false);//聯絡
			                    btnAccept.setDisabled(true);//確認
			                    btnCancel.setDisabled(true);//取消
			                    break;
			                //協力廠商掛斷後
			                case 13:
			                    btnConsult.setDisabled(false);//聯絡
			                    btnAccept.setDisabled(true);//確認
			                    btnCancel.setDisabled(true);//取消
			                    break;
			            }
			} catch (e) {
				
			}


        },
		//轉IVR
		turnIVR:function(){
			try {
				var RetVal;
				var CallParameters = new Object();
                CallParameters["PhoneNumber"] = ivrNumber;
               	CallParameters["TransferInfo"] = CALL_DATA.callId;
                RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2016", CallParameters);
			} catch (e) {
				RetVal = -1;
			}
          		
            if (RetVal == 0) {
            	CALL_DATA.isTurnIVR = "Y";
				if (this.log.isDebugEnabled()) {
                    this.log.debug('轉IVR成功-------------ok');
                }
           	}else {
                Grandsys.sys.Utils.alertError("轉IVR失敗:" + RetVal);
            }	
		},
		//註銷座席
		logOutAgent:function(){
			var CallParameters = new Object();
			CallParameters["Station"] = csrSubCode;
			CallParameters["AgentId"] = csrSPLogin;
			if (this.log.isDebugEnabled()) {
                this.log.debug('csrSubCode:'+csrSubCode+' ,csrSPLogin:'+csrSPLogin);
            }
            var RetVal;
            RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("1004", CallParameters);
			//alert('RetVal:::'+RetVal);
            if (RetVal == 0) {
				//表示從沒有點過就緒
				isFirstAvailable = false;
				//csr沒有登錄softphone
				softPhoneIsLogon = false;
				if (this.log.isDebugEnabled()) {
                    this.log.debug('註銷座席成功-------------ok');
                }
            }
            else {
            	this.log.debug('註銷座席失敗,RetVal:::'+RetVal);
                 Grandsys.sys.Utils.alertError('註銷座席失敗!');
            }
		},
		/**
		 * 供電話作業頁面設置是否處於回訪流程中
		 * @param {Object} careCall   boolean
		 */
		setIsCallCare:function(careCall){
			isCallCare = careCall;
		},
		//關閉ocx進程,關閉表單的時候調用
		beforeUnload:function(){
			if (this.log.isDebugEnabled()) {
                this.log.debug('嘗試關閉CTI');
            }
			var CallParameters = new Object();
            var RetVal;
            RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("1002", CallParameters);
            if (RetVal == 0) {
            	
            	if (this.log.isDebugEnabled()) {
                    this.log.debug('關閉CTI成功-------------ok');
                }
            }
            else {
                Grandsys.sys.Utils.alertError("註銷座席失敗:");
            }

		},
		// 提供給其他地方set這個值
		setCustNumber : function(numbers) {
			custNumbers = numbers;
		},
		// 獲取客戶號碼清單
		getCustNumbers : function() {
			return custNumbers;
		},
		init : function() {
			alert('Ext.SoftPhoneAll');
		},
		//簽入軟電話
		//kevin add for guohua autologin softphone  2010/3/8
		autoLogin:function(mask){
			/*
            var mask = new Ext.LoadMask(parent.document.body, {
                msg: '登入軟電話中,請稍候...',
                removeMask: true
            });
            
            mask.show();
            */
			
			
				var thisp = this;
				
			// 電話資訊初始化
				CALL_DATA = {
					calledNum : '',
					callerNum : '',
					inlineFlag : '',
					callId : '',
					callDirection : '',
					callIntime : '',
					vipCode : '',
					vipType : '',
					callType : '',
					recordFileName:'',
					seqNumber:'',
					recordId:'',
					inlineOrderId:'',
					ringType:'',
					isTurnIVR:'N'
				};
				
				var subcode = Ext.getCmp('csrSubCode');

				var text = '';
				if(subcode!=null){
					text = subcode.getValue();
					// 輸入的值保存起來,下次打開後帶出這個值
					csrSubCode = text;
				}
				//如果沒有分機號，則不簽入
				if(csrSubCode==''||csrSubCode=='initial'){
					if(mask){
							mask.hide();
						}
					return;
				}
				
				// 更新座機顯示
				Ext.SoftPhoneAction.setActInfo('Station_info',csrSubCode);

				var info = {
					csrLogin : csrSPLogin,
					csrPwd : csrSPPwd,
					csrStation : csrSubCode,
					csrUrl : csrUrl,
					csrCurStation:csrCurStation
				}
				
				if (AIC_SYSTEM == 'Demo') {
					if (thisp.log.isDebugEnabled()) {
						thisp.log.debug('demo簽入::GroupNo=='+csrCurStation+',Login::'+csrSPLogin+',Pass:'+csrSPPwd+'---------ok');
					}
					//alert('csrLogin::'+info.csrLogin+',csrPwd::'+info.csrPwd);
					Ext.SoftPhoneAction.setButton(1);
					//document.softphoneocx.SoftPhoneFunction();
					//alert(info.csrLogin+','+info.csrPwd+','+info.csrStation);
				}else if(AIC_SYSTEM == 'Aspect'){
					var RetVal;
					var CallParameters = new Object();
/*
					CallParameters["UserID"] = info.csrLogin;
					CallParameters["Password"] = info.csrPwd;
					CallParameters["StationID"] = info.csrStation;
					RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("1001", CallParameters);
*/

					/*kevin 2009.12.25 for huha*/
					CallParameters["Server"] = info.csrUrl;
					CallParameters["Station"] = info.csrStation;
					CallParameters["AgentId"] = info.csrLogin;
					CallParameters["AgentName"] = '';
					CallParameters["PassWord"] = info.csrPwd;
					CallParameters["GroupNo"] = info.csrCurStation;
					/*
					alert('開始簽入,參數:Server==' + CallParameters.Server+',Station=='+CallParameters.Station+',AgentId=='+CallParameters.AgentId+',AgentName=='+
								CallParameters.AgentName+',PassWord=='+CallParameters.PassWord+',GroupNo=='+CallParameters.GroupNo);
					*/
					RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("1003", CallParameters);
					
					if (thisp.log.isDebugEnabled()) {
						thisp.log.debug('開始簽入,參數:Server==' + CallParameters.Server+',Station=='+CallParameters.Station+',AgentId=='+CallParameters.AgentId+',AgentName=='+
								CallParameters.AgentName+',PassWord=='+CallParameters.PassWord+',GroupNo=='+CallParameters.GroupNo);
					}
					
					if (RetVal == 0) {
						//alert("登錄座席成功:" + RetVal);
						if (thisp.log.isDebugEnabled()) {
							thisp.log.debug('簽入成功---------ok');
						}
						
						Ext.SoftPhoneAction.setButton(1);
						//csr成功登陸softphone
						softPhoneIsLogon = true;
						if(mask){
							mask.hide();
						}
						
					}
					else {
						Grandsys.sys.Utils.alertError('登錄座席失敗,請檢查帳號密碼分機號以及服務器IP是否正確!');
						if(mask){
							mask.hide();
						}
					}
				}
				
		},
		load : function() {
			
			var thisp = this;
			//登錄
			var actLogin = new Ext.Button({
				text : i18n.ShortcutSet.VAR_SOFTPH_TO_LOGIN,
				id : 'actLogin',
				tooltip : {
					text : i18n.ShortcutSet.VAR_SOFTPH_TO_LOGIN,
					title : '',
					autoHide : true
				},
				handler : function() {
					//var iframe = Ext.get('SoftPhoneOCXID').dom;
					//alert('name is::'+iframe.name);
					//alert('id is::'+iframe.id);
					//alert(document.frames.length);
					//window.frames['SoftPhoneOCXID'].SoftPhoneFunction();
					//document.SoftPhoneOCX.SoftPhoneFunction();
					var win = new Ext.Window({
						title : i18n.ShortcutSet.VAR_SOFTPH_TO_LOGIN,
						layout : 'form',
						modal : true,
						labelAlign : 'top',
						resizable : false,
						draggable:false,
						bodyStyle : 'width:100%;padding:5px 5px 0px',
						width : 200,
						items : [{
							xtype : 'textfield',
							id : 'csrSubCode',
							fieldLabel : i18n.ShortcutSet.VAR_SOFTPH_PRINT_SPH,
							allowBlank : false,
							width : 160,
							value : csrSubCode
						}],
						buttons : [{
							text : i18n.ShortcutSet.VAR_SOFTPH_TRUE,
							handler : function() {
								//簽入軟電話
								thisp.autoLogin();
								win.close();
							}
						}, {
							text : i18n.common_Utils.CANELTEXT,
							handler : function() {
								win.close();
							}
						}]
					});

					win.show();

				},
				iconCls : 'Login'
			});

			//登出
			var actLogout = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_TO_LOGOUT,
				id : 'actLogout',
				disabled : true,
				hidden:true,
				tooltip : {
					text : i18n.ShortcutSet.VAR_SOFTPH_TO_LOGOUT,
					title : '',
					autoHide : true
				},
				handler : function() {
					// 更新座席員分機為空
					//Ext.SoftPhoneAction.setActInfo('Station_info', '');
					Ext.SoftPhoneAction.setActInfo('Called_info', '');

					if (AIC_SYSTEM == 'Demo') {
						Ext.SoftPhoneAction.setButton(2);
					} else if (AIC_SYSTEM == 'Aspect') {
						thisp.logOutAgent();
					}
				},
				iconCls : 'Logout'
			});

			//接聽
			var actAccept = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_LISTENER,
				disabled : true,
				//hidden:true,
				tooltip : {
					text : i18n.ShortcutSet.VAR_SOFTPH_LISTENER,
					title : '',
					autoHide : true
				},
				id : 'actAccept',
				handler : function() {
					//接聽時設置變量
					//flag_get_call = true;
					if (AIC_SYSTEM == 'Demo') {
						Ext.SoftPhoneAction.setButton(2);
					} else if (AIC_SYSTEM == 'Aspect') {
						var RetVal;
                        var CallParameters = new Object();
                        RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2002", CallParameters);
                        if (RetVal == 0) {
                        	if (thisp.log.isDebugEnabled()) {
                                thisp.log.debug('接聽成功---------ok');
                            }
                        }
                        else {
                            Grandsys.sys.Utils.alertError('接聽電話失敗!');
                        	//接聽後初使變量
	                   		//flag_get_call = false;
                        }
					}
				},
				iconCls : 'Accept'
			});

			//掛斷
			var actRealse = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_HANGUP,
				disabled : true,
				tooltip : {
					text : i18n.ShortcutSet.VAR_SOFTPH_HANGUP,
					title : '',
					autoHide : true
				},
				handler : function() {
					// 更新座席員分機為空
					//Ext.SoftPhoneAction.setActInfo('Station_info', '');
					Ext.SoftPhoneAction.setActInfo('Called_info', '');
					
					if (AIC_SYSTEM == 'Demo') {
						Ext.SoftPhoneAction.softPhoneEvent('20008');
					}else if (AIC_SYSTEM == 'Aspect') {
						var RetVal;
                        var CallParameters = new Object();
                        RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2003", CallParameters);
                        if (RetVal == 0) {
                        	if (thisp.log.isDebugEnabled()) {
                                thisp.log.debug('掛斷成功---------ok');
                            }
                        }
                        else {
                            Grandsys.sys.Utils.alertError('掛斷電話失敗!');
                        }
					}
				},
				id : 'actRealse',
				iconCls : 'Realse'
			});

			//開始保留
			var actHoldStart = new Ext.Action({
				text : '保留',
				disabled : true,
				tooltip : {
					text : '保留',
					title : '',
					autoHide : true
				},
				id : 'actHoldStart',
				// tag: '1',
				handler : function() {
					if (AIC_SYSTEM == 'Demo') {
						SoftPhoneEvent('20009');
						//Ext.SoftPhoneAction.softPhoneEvent('20009');
					}else if (AIC_SYSTEM == 'Aspect') {
						var RetVal;
                        var CallParameters = new Object();
                        RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2004", CallParameters);
                        if (RetVal == 0) {
                        	if (thisp.log.isDebugEnabled()) {
                                thisp.log.debug('保留成功---------ok');
                            }
                        }
                        else {
                            Grandsys.sys.Utils.alertError('保留電話失敗!');
                        }
					}
				},
				iconCls : 'Hold'
			});
			
			//結束保留
			var actHoldEnd = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_REAGIN,
				disabled : true,
				tooltip : {
					text : i18n.ShortcutSet.VAR_SOFTPH_REAGIN,
					title : '',
					autoHide : true
				},
				id : 'actHoldEnd',
				// tag: '1',
				handler : function() {
					if (AIC_SYSTEM == 'Demo') {
						SoftPhoneEvent('20004');
						//先振鈴
						//Ext.SoftPhoneAction.softPhoneEvent('20004');
						//3秒自動接聽
						//setTimeout("Ext.SoftPhoneAction.softPhoneEvent('20004')",3000);
					}else if (AIC_SYSTEM == 'Aspect') {
						var RetVal;
                        var CallParameters = new Object();
                        RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2005", CallParameters);
                        if (RetVal == 0) {
                        	if (thisp.log.isDebugEnabled()) {
                                thisp.log.debug('結束保留成功---------ok');
                            }
                        }
                        else {
                            Grandsys.sys.Utils.alertError('結束保留電話失敗!');
                        }
					}
				},
				iconCls : 'Hold'
			});

			//撥號
			var actDail = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_DIAL,
				id : 'actDail',
				disabled : true,
				tooltip : {
					text : i18n.ShortcutSet.VAR_SOFTPH_DIAL,
					title : '',
					autoHide : true
				},
//				listeners:{
//					click:function(){
//						alert(5555);
//					}
//				},
				handler:function(){
//					if (thisp.log.isDebugEnabled()) {
//	                     thisp.log.debug('撥號提示判断:'+ flag_save_result +'  --  '+ IS_CALLING);
//	                }
					//话务小结没有保存、已拨或已接电话
					//X掉条件!flag_save_result &&  flag_custmess_open && 话务小节outbound开启、
					if (IS_CALLING) {
						Grandsys.sys.Utils.alertWarn(i18n.CustMess.VAR_CUSTMESS_ALERT_NOSAVE);
						return false;
					}
					
					var paramStr = 'varTypeIds=ea4a721e-a008-405e-995b-572e38acaa4e'
					//同步獲取呼出類型
					var data = Grandsys.sys.Utils.synchronizationRequest(getVarUrl, paramStr, true, 'get');
					
					//combox data
					var callType = data.dataFormServer.var0;
					
					//code和value的對應關係
					var codeValue = data.dataFormServer.codeValue0;
					
					//alert(callType.length);
					
					//預設值
					var defaultValue = data.dataFormServer.varDefault0;
					
					//IP撥號首碼
					var ipDial=data.dataFormServer.ipDial;
					
					//表示回訪的缺省值
					var careCallValue = codeValue.outType02;
					
					//如果沒取到,就置空
					if(careCallValue==null){
						careCallValue = '';
					}
					
                    var win = new Ext.Window({
                        title: i18n.ShortcutSet.VAR_SOFT_OUT_CALL,
                        width: 200,
                        closeAction: 'close',
                        //height:80,
                        resizable: false,
						draggable:false,
                        //border:false,
                        modal: true,
                        items: {
                            xtype: 'panel',
                            layout: 'form',
                            labelAlign: 'top',
                            bodyStyle: 'width:100%;border:0px;background-color:#DFE8F6;padding:5px 5px 0px',
                            items: [{
                                xtype: 'combo',
                                mode: 'local',
                                id: 'callNumber_combo',
                                width : 160,
                                triggerAction: 'all',
                                fieldLabel: i18n.ShortcutSet.VAR_SOFTPH_PRINAT_PHONENUM,
                                allowBlank: false,
                                store: new Ext.data.SimpleStore({
                                    fields: ['display'],
                                    data: Ext.SoftPhoneAll.getCustNumbers()
                                }),
                                displayField: 'display'
                                //value:'123456'
                            }
                            /**
                            ,{
                                xtype: 'combo',
                                mode: 'local',
                                hidden:true,
                                id: 'callType_combo',
                                width : 230,
                                triggerAction: 'all',
                                fieldLabel: '呼出類型',
                                allowBlank: false,
								value:isCallCare?careCallValue:defaultValue,
                                store: new Ext.data.SimpleStore({
                                    fields: ['display','value'],
                                    data: callType
                                }),
                                displayField: 'display',
								valueField:'value',
								allowBlank:false,
								editable:false
                            }**/
                            ]
                        },
                        buttons: [{
                            text: i18n.ShortcutSet.VAR_SOFTPH_DIAL,
                            handler: function(){
                                var text = Ext.getCmp('callNumber_combo').getValue();
                                //外呼的電話放到全域變數裡
								CALLED_NUMBER = text;
                                if (text.length == 0) {
                                    Ext.Msg.alert(i18n.ShortcutSet.VAR_SOFTPH_ERROR, i18n.ShortcutSet.VAR_SOFTPH_PRINAT_PHONENUM);
                                }
                                else {
                                	text=is_number_js(text);
                                	
                                    if (AIC_SYSTEM == 'Demo') {
                                    	SoftPhoneEvent('20002');
                                         //alert("Demo 版的 撥號為："+ text);
                                    }else if(AIC_SYSTEM == 'Aspect'){
										//呼出類型
                                        try {
                                            //var str = Ext.getCmp('callType_combo').getValue();
                                            //var strArray = str.split(',');
                                            //var callType = strArray[0];
                                            //var serviceId = strArray[1];
											//alert('callType::'+callType+'serviceId::'+serviceId)
                                            var RetVal;
                                            var CallParameters = new Object();
                                            //for nissay 所有外撥號碼超過四位的前面加9
                                            var c_text = text;
                                            //if(c_text.length > 4){
                                            //	c_text = "4" + text;
                                            //}
                                            CallParameters["PhoneNumber"] = c_text;
                                            //CallParameters["CallDialType"] = callType; //表示(暫時定義)  0:<默認> 內線   1:AOD_1 外線  2:ACD_1 回訪
                                            //CallParameters["ServiceId"] = serviceId==null?'':serviceId;
                                            RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2001", CallParameters);
                                        } 
                                        catch (e) {
                                            RetVal = -1;
                                        }
                                    
                                        if (RetVal == 0) {
                                        	if (thisp.log.isDebugEnabled()) {
                                                thisp.log.debug('撥號成功,號碼是:'+text+'---------ok');
                                            }
                                        }
                                        else {
                                            Grandsys.sys.Utils.alertError("撥打失敗:" + RetVal);
                                        }
									}
                                    Ext.SoftPhoneAction.setActInfo('Called_info', text);
									
                                    win.close();
                                }
                                
                            }
                        }, {
                            text: i18n.common_Utils.CANELTEXT,
                            handler: function(){
                                win.close();
                            }
                        }]
                    });
                    
                    win.show();
					//如果是回訪，則禁用下拉選單
					if(isCallCare){
						//var combo = Ext.getCmp('callType_combo');
						//combo.disable();
					}
				},

				iconCls : 'Dail'
			});

			//轉接
			var actTransfer = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_BROKE_OVER,
				disabled : true,
				tooltip : {
					text : i18n.ShortcutSet.VAR_SOFTPH_BROKE_OVER,
					title : '',
					autoHide : true
				},
				iconCls : 'Transfer',
				id : 'actTransfer',
				handler : function() {
					ALERT_TYPE = '1';
					showAgent();
				}
					/*
					 * menu: { items: [{ text: '專員...', handler:
					 * onAgentDailClick, ctype: '1' }, { text: '其他號碼...',
					 * handler: onOtherDailClick, tag: VAR_SOFTPH_BROKE_OVER,
					 * ctype: "1" }] }
					 */
			});
			//會議
			var actConference = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_METTING,
				disabled : true,
				tooltip : {
					text : i18n.ShortcutSet.VAR_SOFTPH_METTING,
					title : '',
					autoHide : true
				},
				iconCls : 'Conference',
				id : 'actConference',
				handler : function() {
					ALERT_TYPE = '2';
					showAgent();
				}

			});
			
			//就緒按鈕
			var actAvaliable = new Ext.Action({
				text : '就緒',
				disabled : false,
				tooltip : {
					text : '就緒',
					title : '',
					autoHide : true
				},
				id : 'actAvaliable',
				iconCls : 'Avilable',
				disabled : true,
				handler: function(){
//					if (thisp.log.isDebugEnabled()) {
//	                     thisp.log.debug('就緒提示判断:'+flag_save_result +'--'+ IS_CALLING);
//	                }
					//话务小節inbound只要打開了未保存
//					if(!flag_save_workorderrecord){
//						Grandsys.sys.Utils.alertWarn(i18n.CustMess.VAR_CUSTMESS_ALERT_NOSAVE2);
//						return false;
//					}
					//话务小结没有保存、已拨或已接电话
					//X掉条件!flag_save_result &&  flag_custmess_open && 话务小节outbound开启、
					if (IS_CALLING) {
						Grandsys.sys.Utils.alertWarn(i18n.CustMess.VAR_CUSTMESS_ALERT_NOSAVE);
						return false;
					}
					
					//如果沒有緩存,就從db裡面拿
					if(availableStatus==null){
						//取得就緒狀態
						availableStatus = thisp.getStatusByCode('10002');
					}
					var vstatus = availableStatus;
                    
					//業務上是否可以通過
					var isPass = true;
					
                    if (vstatus != null) {
                        var newCallStatus = {
                            newSrc: vstatus.statusImage,
                            newName: vstatus.statusName,
                            newStatusId: vstatus.statusId,
                            newCallStatus: vstatus.exchangeStatusName,
							newAlertTime:vstatus.alertTime
                        }
                        
                       isPass =  changeStatus(newCallStatus);
                    }
					
					if(AIC_SYSTEM == 'Demo'){
						//alert(isPass);
						Ext.SoftPhoneAction.softPhoneEvent('10002');
						
					}else if (AIC_SYSTEM == 'Aspect') {
						var RetVal;
                        var CallParameters = new Object();
                        
                        if (isPass) {
                        	//因快速和就绪切换，会出现时效問題，两个按钮同事亮起或暂高下拉拉出来后又被置灰的现象，因此在点就绪后就置灰按钮
	                    	actAvaliable.setDisabled(true);//就緒
							actAUX.setDisabled(false);//未就緒
                            if (isFirstAvailable) {
                                //執行業務結束NextCall
                                RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("10002", CallParameters);
                                if (RetVal == 0) {
                                	if (thisp.log.isDebugEnabled()) {
                                        thisp.log.debug('執行就緒成功---------ok');
                                    }
                                }
                                else {
                                	actAvaliable.setDisabled(false);//就緒
									actAUX.setDisabled(true);//未就緒
                                    Grandsys.sys.Utils.alertError('業務結束NextCall出錯!');
                                }
                            }
                            else {
                            	/*var btnAuxmu = Ext.getCmp('Auxmu');
								var btnPausemu = Ext.getCmp('Pausemu');
								btnAuxmu.setDisabled(false);
								btnPausemu.setDisabled(false);*/
								
                                //執行就緒(只會執行一次)
                                RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("10002", CallParameters);
                                //alert(window.frames['SoftPhoneOCXID'].SoftPhoneFunction);
                                if (RetVal == 0) {
                                    isFirstAvailable = true;
                                    	if (thisp.log.isDebugEnabled()) {
                                            thisp.log.debug('執行就緒成功---------ok');
                                        }
                                }
                                else {
                                	actAvaliable.setDisabled(false);//就緒
									actAUX.setDisabled(true);//未就緒
                                    Grandsys.sys.Utils.alertError('就緒出錯!');
                                }
                            }
                        }
                        
					}
				}
			});
			
			/**
			//未就緒
			var actAUX = new Ext.Action({
				text : '未就緒',
				disabled : true,
				id:"Auxmu",
		        tooltip: {text:'未就緒', title:'', autoHide:true},
				iconCls: 'Aux',
				handler: function(){
		        	
		        	var isPass = true;
		        	
					//如果沒有緩存,就從db裡面拿
					if(unAvailableStatus==null){
						//取得就緒狀態
						unAvailableStatus = thisp.getStatusByCode('10001');
					}
					var vstatus = unAvailableStatus;
					
					if (vstatus != null) {
                        var newCallStatus = {
                            newSrc: vstatus.statusImage,
                            newName: vstatus.statusName,
                            newStatusId: vstatus.statusId,
                            newCallStatus: vstatus.exchangeStatusName,
							newAlertTime:vstatus.alertTime
                        }
                        
                       isPass =  changeStatus(newCallStatus);
                    }
					
					logDebug('newCallStatus.newAlertTime is :'+newCallStatus.newAlertTime);
					
	                isPass = changeStatus(newCallStatus);
					//alert(isPass);
					if (AIC_SYSTEM == 'Demo') {
						//alert(isPass);
						Ext.SoftPhoneAction.softPhoneEvent('10001');
					}
					else if (AIC_SYSTEM == 'Aspect') {
	                    
	                    if (isPass) {
	                        //同步到交換機狀態(暫放狀態需特殊處理)
	                        var RetVal;
	                        var CallParameters = new Object();
	                        CallParameters["StatusReason"] = item.exchangeStatusName; //未就緒原因 ID

	                        	RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("10001", CallParameters);
	                            if (RetVal == 0) {
	                                	if (thisp.log.isDebugEnabled()) {
	                                        thisp.log.debug('執行未就緒成功---------ok');
	                                    }
	                            }
	                            else {
	                                Grandsys.sys.Utils.alertError("未就緒失敗:" + RetVal);
	                            }
	                    }
						
					}
		        }
		        
			});
			*/
			
			//leo add 2010-06-08
			//未就緒按鈕
			var auxmenu = new Ext.menu.Menu();
			
			//未就緒按鈕
			var actAUX = new Ext.Toolbar.MenuButton({
		        text: '暫離',
				id:"Auxmu",
		        tooltip: {text:'暫離', title:'', autoHide:true},
				iconCls: 'Aux',
		        menu : auxmenu,
				disabled : true
		    })
		    
		    auxmenu.on('beforeshow', function(){
				auxmenu.removeAll();
                Ext.Ajax.request({
                    url: 'statusManager/statusMgr!getAllStatusByPattern.action',
                    success: function(result, obj){
                        var jsonFromServer = Ext.util.JSON.decode(result.responseText);
                        if (jsonFromServer.success) {
							
                            var status = jsonFromServer.data
							for(var i=0;i<status.length;i++){
								
								var code = status[i].exchangeStatusName;
								//過濾掉一些不需要顯示出來的狀態
								if(notListStatus.indexOf(code)==-1){
                                    auxmenu.add({
                                        text: status[i].statusName,
                                        icon: status[i].statusImage,
                                        alertTime: status[i].alertTime,
                                        statusId: status[i].statusId,
                                        exchangeStatusName: status[i].exchangeStatusName
                                    })
								}
							}
                        }
                        else {
                        }
                    },
                    failure: function(){
                    }
                });
                
            });
            
            auxmenu.on('click',function(menu,item,e){
				var isPass = true;
				
				//如果沒有緩存,就從db裡面拿
				/**
				if(unAvailableStatus==null){
					//取得就緒狀態
					//unAvailableStatus = thisp.getStatusByCode('10001');
					unAvailableStatus = thisp.getStatusByCode(item.exchangeStatusName);
				}
				*/
				
				if(unAvailableStatus == null || unAvailableStatus[item.exchangeStatusName] == null){
					//取得就緒狀態
					//unAvailableStatus = thisp.getStatusByCode('10001');
					var dbstatus = thisp.getStatusByCode(item.exchangeStatusName);
					unAvailableStatus[item.exchangeStatusName] = dbstatus;
				}
				
				var vstatus = unAvailableStatus[item.exchangeStatusName];
				
				if (vstatus != null) {
                       var newCallStatus = {
                           newSrc: vstatus.statusImage,
                           newName: vstatus.statusName,
                           newStatusId: vstatus.statusId,
                           newCallStatus: vstatus.exchangeStatusName,
							newAlertTime:vstatus.alertTime
                       }
                      isPass =  changeStatus(newCallStatus);
                }
				
				//logDebug('newCallStatus.newAlertTime is :'+newCallStatus.newAlertTime);
				
                //isPass = changeStatus(newCallStatus)
                
				if (AIC_SYSTEM == 'Demo') {
					//alert(isPass);
					Ext.SoftPhoneAction.softPhoneEvent('10001');
				}
				else if (AIC_SYSTEM == 'Aspect') {
                    if (isPass) {
                    	//因快速和就绪切换，会出现时效問題，两个按钮同事亮起或暂高下拉拉出来后又被置灰的现象，因此在点就绪后就置灰按钮
                    	actAvaliable.setDisabled(false);//就緒
						actAUX.setDisabled(true);//未就緒
                        //同步到交換機狀態(暫放狀態需特殊處理)
                        var RetVal;
                        var CallParameters = new Object();
                        //CallParameters["StatusReason"] = item.exchangeStatusName; //未就緒原因 ID
						CallParameters["StatusReason"] = item.exchangeStatusName;   //未就緒原因 ID    
                       	RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("10001", CallParameters);
                        if (RetVal == 0) {
                        	if (thisp.log.isDebugEnabled()) {
                                thisp.log.debug('執行未就緒成功---------ok');
                            }
                        }
                        else {
                        	//未就绪失败后还原按钮
                        	actAvaliable.setDisabled(true);//就緒
							actAUX.setDisabled(false);//未就緒
                            Grandsys.sys.Utils.alertError("未就緒失敗:" + RetVal);
                        }
                    }
					
				}
				
			});
			
			//暫放按鈕
			var pausemenu = new Ext.menu.Menu();
			
			//暫放按鈕
			var actPause = new Ext.Toolbar.MenuButton({
		        text: '暫放',
				id:"Pausemu",
		        tooltip: {text:'暫放', title:'', autoHide:true},
				iconCls: 'Aux',
		        menu : pausemenu,
		        hidden:true,
				disabled : true
		    })
			
            pausemenu.on('beforeshow', function(){
				pausemenu.removeAll();
                //清空session,後臺進線客戶
                Ext.Ajax.request({
                    url: 'statusManager/statusMgr!getAllStatusByPattern.action',
                    success: function(result, obj){
                        var jsonFromServer = Ext.util.JSON.decode(result.responseText);
                        if (jsonFromServer.success) {
							
                            var status = jsonFromServer.data
							for(var i=0;i<status.length;i++){
								
								var code = status[i].exchangeStatusName;
								//過濾掉一些不需要顯示出來的狀態
								if(notListStatus.indexOf(code)==-1){
                                    pausemenu.add({
                                        text: status[i].statusName,
                                        icon: status[i].statusImage,
                                        alertTime: status[i].alertTime,
                                        statusId: status[i].statusId,
                                        exchangeStatusName: status[i].exchangeStatusName
                                    })
								}
							}
                        }
                        else {
                        }
                    },
                    failure: function(){
                    }
                });
                
            });
            
            pausemenu.on('click',function(menu,item,e){
				//alert('狀態:'+item.text+'exchangeStatusName:'+item.exchangeStatusName)
				
				var isPass = true;				
                var newCallStatus = {
                    newSrc: item.icon,
                    newName: item.text,
                    newStatusId: item.statusId,
                    newCallStatus: item.exchangeStatusName,
					newAlertTime:item.alertTime
                }
                isPass = changeStatus(newCallStatus);
				if (AIC_SYSTEM == 'Demo') {
					//alert(isPass);
				}
				else if (AIC_SYSTEM == 'Aspect') {
                    
                    if (isPass) {
                        //同步到交換機狀態(暫放狀態需特殊處理)
                        var RetVal;
                        var CallParameters = new Object();
                        CallParameters["StatusReason"] = item.exchangeStatusName; //暫放原因 ID
                        
                        //暫放的原因ID可以取任意一個已經存在的原因ID
                        RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("10001", CallParameters);
                        if (RetVal == 0) {
                        }
                        else if (RetVal == -60) {
                            Grandsys.sys.Utils.alertWarn('本坐席沒有開放暫放許可權');
                            return;
                        }
                        else {
                            Grandsys.sys.Utils.alertError("暫放失敗:" + RetVal);
                        }
                    }
				}
			});
			
			/**
			 * kevin add 20091225 for huha
			 * 單步轉接VDN(滿意度評分)
			 */
			var vdnTransfer = new Ext.Action({
				text : '滿意度',
				id:"vdnTransfer",
		        tooltip: {text:'滿意度', title:'', autoHide:true},
				iconCls: 'Aux',
				disabled : true,
				hidden:true,//kevin增加2010/3/8  國華不需要
				handler : function() {
                    var RetVal;
                    CallParameters = new Object();
                    CallParameters["PhoneNumber"] = vdnNumber   //這個從環境變數裡取,VDN為空即為滿意度評分
                    CallParameters["UUI "] = ''
                    RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2021", CallParameters);
                    if (RetVal == 0) {
                    	if (thisp.log.isDebugEnabled()) {
                            thisp.log.debug('轉vdn成功,vdn號碼是:'+vdnNumber+'---------ok');
                        }
                    }
                    else {
                        Grandsys.sys.Utils.alertError("轉vdn失敗:" + RetVal);
                    }
				}
			});

			/**
			 * 測試進線客戶資料按鈕
			 */
			var refresh = new Ext.Action({
				text : '要速度,就點我',
				handler : function() {
					// refreshIframe();
					MiniWindow();
				}
			});

			//清空狀態碼
			var clearText = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_CLEAN_STATUSCODE,
				handler : function() {
					var el = document.getElementById(document
							.getElementById('codepath'));

					var el2 = document.getElementById(document
							.getElementById('statuspath'));

					var el3 = document.getElementById(document
							.getElementById('direction'));
					el.innerHTML = 'path:';
					el2.innerHTML = 'statuspath:';
					el3.innerHTML = 'direction:';
				}
			});


			//測試來電(非會員)
			var call1 = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_TEST_CALLING,
                handler: function(){
                    //先振鈴
                    Ext.SoftPhoneAction.softPhoneEvent('20001');
                    //1秒自動接聽
                    setTimeout("Ext.SoftPhoneAction.softPhoneEvent('20004')", 1000);
                }
			});

			//測試來電(會員)
			var call2 = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_TEST_CALLINGIS,
				handler : function() {
					Ext.visitWorkerRecord.addCustFormPanel();
				}
			});

			//通話開始
			var call3 = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_CALLING_BEGIN,
				id : 'talkbegin',
				handler : function() {
					//Ext.AvayaSp.updatetoolbar('WORKING', 'WORKING', false);
				}
			});
			
			//lili
			var showContentWindow= new Ext.Action({
               	 text: '知識庫',
              	 handler: function(){	
                	//window.open("content/contentLayout.jsp","_blank","fullscreen=2,menubar=0,toolbar=0,directories=0,location=0,status=0,scrollbars=0");
			  		//window.open('content/contentLayout.jsp','知識庫系統','fullscreen=2,position:absolute;top:150;left:0; scroll,width=800px,height=600px,scrollbars=yes')
					window.open('content/contentLayout.jsp','知識庫系統','resizable=yes,reposition:absolute;top:150;left:0; scroll,width=800px,height=600px,scrollbars=yes')
                }
            });
			
			//軟電話工具按鈕
			var tb = new Ext.Toolbar({
				id:'softphoneToolBar'
			});
			tb.render('softPhonebar');

			tb.add(actLogin, actLogout,'-',actAvaliable,actAUX,'-',actPause,actAccept, actRealse,
					actHoldStart, actHoldEnd, actDail, '-', actTransfer,actConference,vdnTransfer
					/*
						, '-', {
							xtype : 'panel',
							border : false,
							id : 'link_status_show',
							// bodyStyle: 'background-color:#D3E1F1;',
							bodyStyle : 'background: transparent;',
							html : '&nbsp;&nbsp;&nbsp<img id="linkStatusImg" src="../images/softphone/red.png" alt="連接中斷"/>'
						}
					*/
					);

			//登出按钮
			var logOutButton = new Ext.Action({
				text : i18n.ShortcutSet.VAR_LOGOUT,
				bodyStyle : 'padding-left:20;',
				tooltip : {
					text : i18n.ShortcutSet.VAR_LOGOUT,
					title : '',
					autoHide : true
				},
				iconCls : 'logOut',
				handler : function() {
					SafeOut();
				}
			});
			tb.add('-',logOutButton);	
//			tb.add({
//					xtype : 'panel',
//					border : false,
//					bodyStyle : 'padding-left:20; background: transparent;',
//					html: '<a href="#" onclick="SafeOut()"/><img src="../images/logout.png" />'
//			})
//			tb.add(new Ext.form.Label({
//						text : '登出'
//					}));
			tb.addFill();

			//demo版本增加一個測試來電按鈕
			if(AIC_SYSTEM == 'Demo'){
				tb.add(call1);
				//tb.add(call2);
			}
			
			tb.add({
				xtype : 'panel',
				border : false,
				// bodyStyle: 'background-color:#D3E1F1;',
				bodyStyle : 'background: transparent;',
				html: '<img src="../images/logo-small.png" />'
			});

			var AgentID = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_ZHUANYU,
				id : 'AgentID'
			});

			var Station = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_SIT_PHONE,
				id : 'Station_info'
			});

			var Caller = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_CENTER_NUM,
				id : 'Caller_info'
			});

			var Called = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_CUST_NUM,
				id : 'Called_info'
			});

			var WorkSataus = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_WORK_TYPE,
				id : 'WorkSataus_info'
			});

			var WorkGroup = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SETGRID_WORK_GROUP,
				id : 'WorkGroup_info'
			});
			var Btn_VIP_Info = new Ext.Action({
				text : '<font color="#ff0044"><i><b>VIP&nbsp;&nbsp;</b></i></font>',
				id : 'btn_aviva_calling_vip_info20090827',
				iconCls : 'vip-info',
				disabled:true,
				handler:function(){
					var  vipInfoWin= new com.grandsys.softphone.vip.AvivaVIPSoftphone();
					vipInfoWin.initVIPCusInfos();
				}
			});
			
			// var AgentID = new Ext.Toolbar.TextItem('AgentID: ****');
			// var Station = new Ext.Toolbar.TextItem('Station: ****');
			// var AgentSataus = new Ext.Toolbar.TextItem('AgentSataus: ****');

			var tb2 = new Ext.Toolbar();
			tb2.render('softPhonebar');

			tb2.add(Station, '-', Caller, '-', Called, '-', WorkSataus, '-',
					WorkGroup);//,'-', Btn_VIP_Info
					
			tb2.addFill();
			
			tb2.add(showContentWindow);

			var ext1 = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_ZHUANYU,
				id : 'btnmute'
			});

			var ext2 = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_SIT_PHONE,
				id : 'btnblindtransfer'
			});

			var ext3 = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_CENTER_NUM,
				id : 'btnconsulttransfer'
			});

			var ext4 = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_CUST_NUM,
				id : 'btncanceltransfer'
			});

			var ext5 = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SOFTPH_WORK_TYPE,
				id : 'btnconsultconference'
			});

			var ext6 = new Ext.Action({
				text : i18n.ShortcutSet.VAR_SETGRID_WORK_GROUP,
				id : 'btncancelconference'
			});

			var tb3 = new Ext.Toolbar();

			tb3.render('softPhonebar');

			tb3.add(ext1, ext2, ext3, ext4, ext5, ext6);

			tb3.hide();

			/**
			 * 連後臺獲取csr基本資訊
			 */
			var conn = Ext.lib.Ajax.getConnectionObject().conn;

			var url = getCsrInfoUrl;//
			conn.open("GET", url, false);// false表示同步調用
			conn.send(null);
			var data = Ext.util.JSON.decode(conn.responseText);

			var wkName = data.wkName;
			var wpName = data.wpName;
			var csrNumber = data.csrNumber;
			
			if(null == data.wpName || '' == data.wpName) {
				wpName = "預設工作模式";
			}

			Ext.SoftPhoneAction.setActInfo('WorkGroup_info', wkName);
			Ext.SoftPhoneAction.setActInfo('WorkSataus_info', wpName);
			Ext.SoftPhoneAction.setActInfo('Caller_info', csrNumber);
			
			// 設置csr分機號
			if (csrSubCode == 'initial') {
				csrSubCode = data.csrSubCode;
			}
			
			csrSPLogin = data.csrSoftPhoneLogin; // 設置軟電話登錄用戶名
			csrSPPwd = data.csrSoftPhonePwd; // 設置軟電話登錄密碼
			csrUrl = data.csrSoftPhoneUrl; // 設置登錄的交換機url
			csrCurStation = data.curStation;//座席員當前分機位置(huha裡面代表ACD Group);
			vdnNumber = data.vdnNumber;//vdn號碼
			
			//laidianhaoma fanwei
			CALL_IN_NUMBERS = data.callnumbers;
			
			/** ***************更新座席員的資訊結束*************** */
			
			//alert(csrSubCode);

			/*
			 * // functions to display feedback function onButtonClick(btn){
			 * Ext.example.msg('Button Click', 'You clicked the "{0}" button.',
			 * btn.text); }
			 * 
			 * function onItemClick(item){ Ext.example.msg('Menu Click', 'You
			 * clicked the "{0}" menu item.', item.text); }
			 * 
			 * function onItemCheck(item, checked){ Ext.example.msg('Item
			 * Check', 'You {1} the "{0}" menu item.', item.text, checked ?
			 * 'checked' : 'unchecked'); }
			 * 
			 * function onItemToggle(item, pressed){ Ext.example.msg('Button
			 * Toggled', 'Button "{0}" was toggled to {1}.', item.text,
			 * pressed); }
			 */
			function onOtherDailClick(item) {
				Ext.Msg.prompt(item.text + item.tag,
						i18n.ShortcutSet.VAR_SOFTPH_PRINAT_PHONENUM, function(
								btn, text) {
							if (btn == 'ok' && text) {
								// alert(item.tag);
								if (item.ctype == "1") {

								} else {

								}

							}
							if (btn == 'ok' && !text) {
								Ext.Msg.alert(
										i18n.ShortcutSet.VAR_SOFTPH_ERROR,
										i18n.ShortcutSet.VAR_SOFTPH_TRUE_NUM);
							}
						});
			}

			function onOtherDailClick2(item) {
				Ext.Msg.prompt(item.text,
						i18n.ShortcutSet.VAR_SOFTPH_PRINAT_PHONENUM, function(
								btn, text) {
							if (btn == 'ok' && text) {

							}
						});
			}

			function onAgentDailClick(item) {
				showAgent(item);
			}
			

			/*
			 * function onQueueDailClick(item){ showQueue(item); }
			 */
			var record = Ext.data.Record.create([{
				name : 'VUserCode'
			}, {
				name : 'VSubcode'
			}, {
				name : 'VUserCname'
			}, {
				name : 'wkMoshi_Description'
			}]);

			var dataStore = new Ext.data.Store({
				url : getInfoUrl,
				reader : new Ext.data.JsonReader({
					totalProperty : 'totalProperty',
					root : 'root'
				}, record)
			});

			dataStore.baseParams = {
				c_name : '',
				c_userTitle : '',
				c_deptId : '',
				c_descBy : '',
				c_userCode : '',
				c_roleId : '',
				c_skg : ''
			}

			// grid選擇模型
			var sm = new Ext.grid.RowSelectionModel();

			// create the Grid
			var grid = new Ext.grid.GridPanel({
				sm : sm,
				store : dataStore,
				// frame:true,
				id : 'agentgrid',
				bodyStyle : 'width:100%;border:1px solid #99bbe8;',
				columns : [{
					header : i18n.ShortcutSet.VAR_SOFTPH_WORK_CRY,
					width : 60,
					sortable : true,
					dataIndex : 'VUserCode'
				}, {
					header : i18n.ShortcutSet.VAR_SOFTPH_NAME,
					width : 75,
					sortable : true,
					dataIndex : 'VUserCname'
				}, {
					header : i18n.ShortcutSet.VAR_SOFTPH_FENJI,
					width : 75,
					sortable : true,
					dataIndex : 'VSubcode'
				}		// {header: "狀態", width: 75, sortable: true, dataIndex:
						// 'Status'}
				],
				stripeRows : true,
				tbar : [{
					text : i18n.common_Utils.hideQueryCondition,
					tooltip : i18n.common_Utils.hideshowConditiuon,
					id : 'hideBtn',
					handler : function() {
						var obj_hide = Ext.getCmp('hideBtn');

						var obj_queryID = Ext.getCmp('queryBtn');

						if (obj_hide.getText() == i18n.common_Utils.hideQueryCondition) {
							obj_hide.setText(i18n.common_Utils.showCondition);
							obj_hide.setIconClass('ShowConditions');
							obj_queryID.setDisabled(true);

						} else if (obj_hide.getText() == i18n.common_Utils.showCondition) {
							obj_hide
									.setText(i18n.common_Utils.hideQueryCondition);
							obj_queryID.setDisabled(false);
							obj_hide.setIconClass('HideConditions');
						}
						query_form.toggleCollapse(true);
					},
					iconCls : 'HideConditions'
				}, '-', {
					text : i18n.common_Utils.query,
					tooltip : i18n.common_Utils.COMMIT_QUERY,
					id : 'queryBtn',
					handler : function() {
						dataStore.baseParams = {
							c_name : Ext.getCmp('csrname').getValue(),
							c_userTitle : '',
							c_deptId : '',
							c_descBy : '',
							c_userCode : '',
							c_roleId : '',
							c_skg : ''
						}
						dataStore.load({
							params : {
								start : 0,
								limit : SYS_CONSTANT_PAGESIZE
							}
						});
					},
					iconCls : 'Quarry'
				}, '-', {
					text : i18n.ShortcutSet.VAR_SOFTPH_CALLING_WORD,
					id : 'btnConsult',
					iconCls : 'set',
					handler : function() {
						var csrCode = Ext.getCmp('phone_number_id').getValue();
						if (csrCode == '') {
							Grandsys.sys.Utils
									.alertWarn(i18n.ShortcutSet.VAR_SOFTPH_CHOSE_CSR);
							return;
						} else {
							// csrCode = csrSelected.get('VSubcode');
							//協議轉接
							
							if (ALERT_TYPE == '1') {
								if (AIC_SYSTEM == 'Demo') {
									Ext.SoftPhoneAll.optBtn(1);
									
								}else if(AIC_SYSTEM == 'Aspect'){
                                    var RetVal;
                                    var CallParameters = new Object();
                                    
                                    /*
                                     * 取得介面上輸入的訂單號
                                     * 如果ivr裡沒有訂單好則取這個
                                     */
                                    var inputOrderId = '';
                                    var orderField = Ext.getCmp('IB_inline_order_id');
                                    if(orderField!=null){
                                    	inputOrderId = orderField.getValue();
                                    }
                                    
                                    //轉接的訂單號
                                    var trans_orderId = '';
                                    
                                    /**
                                     * 先取ivr的訂單號，沒有再取介面上輸入的
                                     */
                                    if (CALL_DATA.inlineOrderId != null
															&& CALL_DATA.inlineOrderId != '') {
                                    	trans_orderId = CALL_DATA.inlineOrderId;
									}else if(inputOrderId!=''){
										trans_orderId = inputOrderId;
									}
                                    
                                    
                                    //CallParameters["PhoneNumber"] = csrCode;
                                    //RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2006", CallParameters);
									
									//kevin 20091225 for huha  
									//CallParameters["TransferInfo"]='8837037';
									CallParameters["PhoneNumber"]=csrCode;
									CallParameters["TransferInfo"]=trans_orderId;
                                    RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2006", CallParameters);
									
                                    if (RetVal == 0) {       
                                       	CALL_DATA.isTurnIVR = "N";//協議轉接聯絡成功時將是否轉IVR清為“N”
                                    	if (thisp.log.isDebugEnabled()) {
                                            thisp.log.debug('協議轉接成功,參數是::'+CallParameters.TransferInfo+'-------------ok');
                                        }
						//alert('before change optBtn::');
										Ext.SoftPhoneAll.optBtn(1);
						//alert('after change optBtn::');
                                    }
                                    else {
										Grandsys.sys.Utils.alertError("二步 轉接:接通失敗:" + RetVal);
                                    }
								}
							//協議會議
							} else {
								if(AIC_SYSTEM == 'Demo'){
									Ext.SoftPhoneAll.optBtn(1);
								}else if(AIC_SYSTEM == 'Aspect'){
									var RetVal;
                                    var CallParameters = new Object();
                                    //CallParameters["PhoneNumber"] = csrCode;
                                    //RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2009", CallParameters);
									//kevin 20091225 for huha
									CallParameters["PhoneNumber"]=csrCode;
									CallParameters["TransferInfo"]='';//暫時沒有,傳空
                                    RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2009", CallParameters);
									
                                    if (RetVal == 0) {            
                                       	CALL_DATA.isTurnIVR = "N";//協議會議聯絡成功時將是否轉IVR清為“N”
                                    	if (thisp.log.isDebugEnabled()) {
                                            thisp.log.debug('協議會議成功-------------ok');
                                        }
                                        Ext.SoftPhoneAll.optBtn(1);
                                    }
                                    else {
                                        Grandsys.sys.Utils.alertError("二步 會議:接通失敗:"+RetVal);
                                    }
								}
							}

						}
					}
				}, '-', {
					text : ALERT_TYPE == '1'
							? i18n.ShortcutSet.VAR_SOFTPH_TRUE
							: i18n.ShortcutSet.VAR_SOFTPH_TRUE,
					id : 'btnAccept',
					iconCls : 'set',
					disabled:true,
					handler : function() {
						//確認轉接
						if (ALERT_TYPE == '1') {
                            if (AIC_SYSTEM == 'Demo') {
                            	Ext.SoftPhoneAll.optBtn(2);
                            }
                            else if (AIC_SYSTEM == 'Aspect') {
								var CallParameters = new Object();
                                var RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2007", CallParameters);
                                if (RetVal == 0) {
                                	if (thisp.log.isDebugEnabled()) {
                                        thisp.log.debug('確認轉接成功-------------ok');
                                    }
									Ext.SoftPhoneAll.optBtn(2);
                                }
                                else {
                                    Grandsys.sys.Utils.alertError("二步 轉接:確定失敗:" + RetVal);
                                }
                            }
						//確認會議
						} else {
							if (AIC_SYSTEM == 'Demo') {
								Ext.SoftPhoneAction.softPhoneEvent('20007');
								Ext.SoftPhoneAll.optBtn(2);
							}
							else if (AIC_SYSTEM == 'Aspect') {
								var CallParameters = new Object();
								var RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2010", CallParameters);
								if (RetVal == 0) {
									if (thisp.log.isDebugEnabled()) {
					                    thisp.log.debug('確認會議成功-------------ok');
					                }
									Ext.SoftPhoneAll.optBtn(2);
								}
								else {
									Grandsys.sys.Utils.alertError("二步 會議:確定失敗:" + RetVal);
								}
							}
						}
						winAgent.hide();
					}
				}, '-', {
					text : i18n.common_Utils.CANELTEXT,
					id : 'btnCancel',
					iconCls : 'cancel',
					disabled:true,
					handler : function() {
						//取消轉接
						if (ALERT_TYPE == '1') {
							if (AIC_SYSTEM == 'Demo') {
								Ext.SoftPhoneAll.optBtn(2);
							}
							else if (AIC_SYSTEM == 'Aspect') {
								CallParameters = new Object();
								var RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2008", CallParameters);
								if (RetVal == 0) {
									if (thisp.log.isDebugEnabled()) {
					                    thisp.log.debug('取消轉接成功-------------ok');
					                }
									Ext.SoftPhoneAll.optBtn(2);
								//alert("二步 會議:確定成功:" + RetVal);
								}
								else {
									Grandsys.sys.Utils.alertError("二步 轉接:取消失敗:" + RetVal);
								}
							}
						//取消會議
						} else {
							if (AIC_SYSTEM == 'Demo') {
								Ext.SoftPhoneAll.optBtn(2);
							}
							else if (AIC_SYSTEM == 'Aspect') {
								CallParameters = new Object();
								var RetVal = window.frames['SoftPhoneOCXID'].SoftPhoneFunction("2011", CallParameters);
								if (RetVal == 0) {
									if (thisp.log.isDebugEnabled()) {
					                    thisp.log.debug('取消會議成功-------------ok');
					                }
									Ext.SoftPhoneAll.optBtn(2);
								//alert("二步 會議:確定成功:" + RetVal);
								}
								else {
									Grandsys.sys.Utils.alertError("二步 會議:取消失敗:" + RetVal);
								}
							}
						}
						//winAgent.hide();
					}
				}, '-', {
					text : i18n.ShortcutSet.VAR_SOFTPH_CLOSE,
					iconCls : 'remove',
					handler : function() {
						winAgent.hide();
					}
				}, '-', i18n.ShortcutSet.VAR_SOFTPH_CALL_NUMBER + ':', {
					fieldLabel : i18n.ShortcutSet.VAR_SOFTPH_CALL_NUMBER,
					xtype : 'textfield',
					id : 'phone_number_id',
					width : 50
				}],
				bbar : new Ext.PagingToolbarEx({
					pageSize : SYS_CONSTANT_PAGESIZE,
					// pageSize: 1,
					store : dataStore,
					id : 'pagetoolbar_csrname',
					displayInfo : true,
					displayMsg : i18n.common_Utils.displayMsg,
					nextText : i18n.common_Utils.nextPage,
					lastText : i18n.common_Utils.lastText,
					firstText : i18n.common_Utils.firsttext,
					prevText : i18n.common_Utils.prevText,
					refreshText : i18n.common_Utils.refreshText,
					afterPageText : i18n.common_Utils.afterPageText,
					beforePageText : i18n.common_Utils.beforePageText,
					emptyMsg : i18n.common_Utils.emptyMsg
				}),
				viewConfig : {
					forceFit : true
				}
					// autoExpandColumn: 'agentid'
					// height: 160,
					// width: 400

			});

			var query_form = new Ext.form.FormPanel({
				autoWidth : true,
				bodyStyle : 'padding:8px;border:0px;border-bottom:1px solid #99bbe8;background-color:#DFE8F6',
				labelWidth : 80, // 文字的寬度
				align : 'center',
				url : '', // 提交後的action地址
				id : 'inlineListQuery',
				collapsible : true,
				items : [{
					layout : 'column',
					bodyStyle : 'border:0px;background-color:#DFE8F6',
					items : [{
						columnWidth : .5,
						layout : 'form',
						labelWidth : 50,
						bodyStyle : 'border:0px;background-color:#DFE8F6',
						items : [{
							xtype : 'textfield',
							fieldLabel : i18n.ShortcutSet.VAR_SOFTPH_NAME,
							name : 'first',
							id : 'csrname'
						// allowBlank: false
						}]
					}]
				}]
			});
			var winAgent;

			grid.add(query_form);

			grid.on('rowclick', function(grid2, row, e) {
				var store = grid2.getStore();
				var red = store.getAt(row);
				//Ext.getCmp('phone_number_id').setValue(red.get('VSubcode')); //20110510 for kinmen
				Ext.getCmp('phone_number_id').setValue(red.get('VUserCode'));
			});

			function showAgent() {
				// alert(item.ctype);

				// 要轉接或要加入會議的專員號碼
				var csrCode = '';
				var csrType = '3';
				var otherCode = '';

				// if (!winAgent) {
				winAgent = new Ext.Window({
					title : i18n.ShortcutSet.VAR_SOFTPH_PHONE_BOOK,
					width : 500,
					height : 300,
					layout : 'fit',
					closeAction : 'hide',
					plain : true,
					modal : false
						// items: grid,
						// bbar: toolbar
				});
				// }

				winAgent.add(grid);
				winAgent.show();
				dataStore.load({
					params : {
						start : 0,
						limit : SYS_CONSTANT_PAGESIZE
					}
				})
				
				

			}

		}
	}
}();

//=============================================================
/**
* 判斷電話號碼必須為數位 
* @return num
*/

//只能是數位， 非數位則刪除
function is_number_js(element_name){
	element_name=element_name.replace(/[^\d]/g,'');
	return element_name;
}
